package com.gms.service.placemanager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gms.entity.place.PlaceNotice;
import com.gms.mapper.placemanager.PlaceNoticeMapper;
import com.gms.service.placemanager.PlaceNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlaceNoticeServiceImpl extends ServiceImpl<PlaceNoticeMapper, PlaceNotice> implements PlaceNoticeService {

    @Autowired
    PlaceNoticeMapper placeNoticeMapper;

    @Override
    public PlaceNotice SelectPlaceNoticeNew() {
        QueryWrapper<PlaceNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("notice_date");
        queryWrapper.eq("notice_state","正常");
        placeNoticeMapper.selectList(queryWrapper);
        return placeNoticeMapper.selectList(queryWrapper).get(0);
    }

    @Override
    public List<PlaceNotice> SelectAllPlaceNotice() {
        QueryWrapper<PlaceNotice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("notice_state","正常");
        return placeNoticeMapper.selectList(queryWrapper);
    }

    @Override
    public void InsertPlaceNotice(PlaceNotice placeNotice) {
        placeNoticeMapper.insert(placeNotice);
    }

    @Override
    public void DeletePlaceNotice(Integer noticeid) {
        UpdateWrapper<PlaceNotice> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("notice_state","已删除");
        updateWrapper.eq("notice_id",noticeid);
    }
}
